<!DOCTYPE html>
<html class="um landscape min-width-240px min-width-320px min-width-480px min-width-768px min-width-1024px">
    <head>
        <title></title>
        <meta charset="utf-8">
        <meta name="viewport" content="target-densitydpi=device-dpi, width=device-width, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
        <link rel="stylesheet" href="css/fonts/font-awesome.min.css">
        <link rel="stylesheet" href="css/ui-box.css">
        <link rel="stylesheet" href="css/ui-base.css">
        <link rel="stylesheet" href="css/ui-color.css">
        <link rel="stylesheet" href="css/appcan.icon.css">
        <link rel="stylesheet" href="css/appcan.control.css">
        <link rel="stylesheet" href="css/scDetail.css">
    </head>
    <body class="um-vp bc-bg" ontouchstart style="background:#ffffff">
      <div class="sc_title">
      </div>
      <div id="page_box">
      </div>
    <!--   <div id="toUpgrade">
       <p class="ub ub-ac ub-pc">一键升舱</p>
      </div> -->
    </body>
    <script src="js/appcan.js"></script>
    <script src="js/appcan.control.js"></script>
    </body>
    <script>
        appcan.ready(function(){
          appcan.locStorage.remove("toUpgrade");
          userList();
          pullToRefresh_loadMore();
        });
        //获取用户信息的方法
        // var path="http://mgstest.ceair.com:8080/mpservice/";
        //var path="http://172.31.3.190:8080/mpservice/";
          var path="http://mpservice.ceair.com/mpservice/";
        var flightNo=appcan.locStorage.getVal("flightNo");//缓存的的航班号码
        var flightDate=appcan.locStorage.getVal("flightDate");//飞行日期
        var Carrier=appcan.locStorage.getVal("Carrier");//承运人
        function userList(){
            appcan.window.openToast("数据加载中...","",5,1);
            //var PlatinumCardNum=appcan.locStorage.getVal("PlatinumCardNum");
            var url=path+"platinum_getCustomerInfoByFlightInfo.action?Carrier="+Carrier+"&flightNo="+flightNo+"&flightDate="+flightDate+"";
            $.ajax({
              url:url,
              data:"",
              type:"GET",
              success:function(data){
                console.log(data)
                appcan.window.closeToast();
                // console.log(url);
                // console.log(data.length);
                appcan.locStorage.remove("setBounce");
                if(data.length ==0){
                  appcan.window.confirm("提示","暂无旅客信息","确定",function(){
                      uexWindow.evaluateScript("scDetail", "0", "appcan.window.close(-1)");
                      uexWindow.evaluatePopoverScript("bjscPage", "content", "reflog()");
                      return;
                  })
                }
                appcan.window.closeToast();
                var count=0;
                var res="";
                var checkType="";
                var PlatinumCardNum=data.length;
                for(var i=0;i<data.length;i++){
                        var seatNo="";//新的座位号
                        var SEQ=data[i].SEQ;//页面排序的序号;
                        var paxName=data[i].paxName;//白金升舱用户名
                        var boardingNO=data[i].boardingNO;//值机编号
                        var standByTime=(data[i].standByTime).substr(5);//登记时间；
                        var oldCabin=data[i].oldCabin;//旧舱位；
                        var newCabin=data[i].newCabin;//新舱位；
                        var status=data[i].status;//客票状态;
                        var idNum=data[i].idNum;//旅客证件信息
                        var idType=data[i].idType;//证件类型
                        var isupgra;
                        if(newCabin!==""&&newCabin!==oldCabin){
                          //当有新舱位的时候 并且不等于旧舱位的时候  显示新的座位号;
                          seatNo=data[i].seatNo;
                          count++;//当有新座位的时候   在已经处理的基础上加1；
                          checkType="checkbox3";
                          isupgra="true";
                        }else{
                          seatNo="";//没有新舱位  不显示新座位号;
                          checkType="checkbox";
                          isupgra="false";
                        }
                        // console.log(standByTime);
                        SEQ=(SEQ<10)?"0"+SEQ:SEQ;
                        paxName=(paxName==""||paxName==null)?"---":paxName;
                        boardingNO=(boardingNO==""||boardingNO==null)?"---":boardingNO;
                        oldCabin=(oldCabin==""||oldCabin==null)?"---":oldCabin;
                        newCabin=(newCabin==""||newCabin==null)?"---":newCabin;
                        status=(status==""||status==null)?"---":status;
                        res+='<div class="detail_main ub ub-ver">'
                                      +'<div class="user_title ub ub-ac">'
                                        +'<div class="'+checkType+' umar-r" idNum='+idNum+' idType='+idType+' isupgra='+isupgra+'>'
                                        +'</div>'
                                        +SEQ+'&nbsp;&nbsp;<span class="paxName">'+paxName+'</span>&nbsp;<i>BNO('+boardingNO+')</i>'
                                      +'</div>'
                                      +'<div class="ub main_box">'
                                              +'<div class="ub ub-ac ub-pc ub-ver" style="width:35%;">'
                                                +'<p>'+standByTime+'</p>'
                                                +'<span>登记时间</span>'
                                              +'</div>'
                                              +'<div class="ub ub-ac ub-pc" style="width:30%;">'
                                                  +'<div class="ub  ub-ac ub-pc ub-ver" style="width:50%">'
                                                    +'<p style="color:#48BF7F">'+oldCabin+'</p>'
                                                    +'<span>旧舱位</span>'
                                                  +'</div>'
                                                   +'<div class="ub  ub-ac ub-pc ub-ver" style="width:50%">'
                                                    +'<p style="color:#48BF7F" class="newCabin">'+newCabin+'</p>'
                                                    +'<span>新舱位</span>'
                                                  +'</div>'
                                              +'</div>'
                                              +'<div class="ub ub-ac ub-pc ub-ver" style="width:35%;">'
                                                +'<p class="status">'+status+'</p>'
                                                +'<span>客票状态</span>'
                                              +'</div>'
                                      +'</div>'
                                      +'<div class="ub ub-ac ">'
                                        +'新座位:&nbsp;<i class="newseat">'+seatNo+'</i>'
                                      +'</div>'
                                  +'</div>';
                    }
                    $("#page_box").html(res);
                    var tips=$('<div class="ub ub-f1 ub-ac">'
                                  +'<p> 已申请:<i style="color:#48BF7F" class="applied">'+PlatinumCardNum+'</i></p>'
                                +'</div>'

                                +'<div class="ub ub-ac ub-f1">'
                                  +'<p>已升舱:<i style="color:#48BF7F" class="Upgraded">'+count+'</i></p>'
                                +'</div>');
                    $(".sc_title").html(tips);
                    $(".sc_title").addClass("ub ub-ac ub-pc");
                    $(".sc_title").css("display","block");
                    $(".checkbox").click(function(){
                      var a=$(this).attr("isupgra");
                      if(a !=="true"){
                        $(this).toggleClass("checkbox2");
                      }else{
                        return false;//当已经升舱升舱了  就不能再次勾选 ;
                      }
                    })
                    $("#toUpgrade").css("display","block");
                    $("#toUpgrade").addClass("ub ub-ac ub-pc");
              },
              error:function(data){
                    //console.log(data)
                    appcan.window.openToast("无法连接到服务器，请稍后再试...",2000,5,0);
              }
            })
        }
        //一键升舱 点击按钮
        function doUpgrade(){
          var customerInfo=[];
          var upgradeArr=$(".user_title .checkbox2");//获取已经勾选的升舱旅客信息
          var isUpgrade=appcan.locStorage.getVal("toUpgrade");
          for(var i =0;i<upgradeArr.length;i++){
            var obj={}
            var a=upgradeArr[i];
            obj.idType=$(a).attr("idType");
            obj.idNum=$(a).attr("idNum");
            customerInfo.push(obj);
          }
          if(isUpgrade !=="true"){
              var applied=$(".applied").text();//获取已经申请的数量
              var Upgraded=$(".Upgraded").text();//获取已经升舱的数量;
              if(Number(applied)==Number(Upgraded)){
                    appcan.window.openToast("当前申请升舱旅客,已全部升舱..",2500,5,0);
                    return false;
              }else if(customerInfo.length==0){
                appcan.window.openToast("请先选择要升舱的旅客...",2500,5,0);
                return false;
              }else{
                appcan.locStorage.setVal("toUpgrade","true");//当执行请求的时候 保存本地一个状态
                customerInfo=JSON.stringify(customerInfo);
                toUpgrade(customerInfo);
             }
          }else{
            //在没有请求成功之前   不允许操作 防止点击频率过高;
            return false;
          }
        }
        //一键升舱方法;
        function toUpgrade(cust){
          appcan.window.openToast("操作中，请稍后...","",5,1);
          var deptAirport=appcan.locStorage.getVal("dep");//出发航站三字码;
          var arrAirport=appcan.locStorage.getVal("arr");//到达航站三字码;
          var loginName=localStorage['MU30-lOGIN-USRNAME'];//当前操作人
          var carrier=appcan.locStorage.getVal("Carrier");
          //var loginName="CHENGCHENG1";
          var url=path+"platinum_executeUPG.action?flightNo="+flightNo+"&flightDate="+flightDate+"&deptAirport="+deptAirport+"&arrAirport="+arrAirport+"&carrier="+carrier+"&loginName="+loginName+"&customerInfo="+cust;
          var detail_main=$(".detail_main");
          $.ajax({
            url:url,
            type:"GET",
            data:"",
            success:function(pareams){
                appcan.window.closeToast();
                appcan.locStorage.remove("toUpgrade");//请求成功移除提交状态 
                console.log(pareams);
                console.log(url);
                var status=pareams.status;
                console.log(status);
                var result=pareams.result;
                var Upgraded=Number($(".Upgraded").text());
                if(status==1){
                  var success=0;
                  var fal=0;
                  for(var i =0; i<result.length;i++){
                        var obj=result[i];
                        var newCabin=obj.newCabin;//获取新舱位;
                        var oldCabin=obj.oldCabin;//获取旧舱位
                        var seatNo=obj.seatNo;//新座位;
                        var paxName=obj.paxName;//旅客姓名;
                        var idNums=obj.idNum;//获取返回的 id 证件号
                        var idTypes=obj.idType;//返回的证件类型
                        var statuss=obj.status;
                        var isSuccess=obj.isSuccess;//判断是否操作成功
                        if(newCabin!==""&&isSuccess==true&&newCabin!==oldCabin){
                          //当新舱位不为空  且状态成功 且不等于旧舱位的时候
                          Upgraded++;
                          success++;
                          $(".Upgraded").text(Upgraded);//升舱成功  已升舱数量+1；
                          for(var z=0;z<detail_main.length;z++){
                            var box=detail_main[z];
                            var idNum=$(box).find(".checkbox").attr("idNum");//获取文本 中每个元素的 id证件号
                            var idType=$(box).find(".checkbox").attr("idType");//获取文本中 每个元素的 证件类型;
                            if(idNums==idNum&&idTypes==idType){//证件号 对号入座
                              $(box).find(".newCabin").text(newCabin);
                              $(box).find(".newseat").text(seatNo);
                              var classTYpe=$(box).find(".checkbox").attr("class");
                              var classTYpe2=classTYpe.replace("checkbox2","checkbox3");
                              $(box).find(".checkbox").attr("class",classTYpe2);
                              $(box).find(".checkbox").attr("isupgra","true");
                              $(box).find(".status").text(statuss);
                            }
                          }
                        }else if(isSuccess==false){
                          fal++;
                        }
                  }
                    appcan.window.alert("操作成功","成功:"+success+"人,失败:"+fal+"人","确定");
                }else{
                 appcan.window.alert("提示","操作失败","确定",function(){
                    userList();
                  })
                }
            },
            error:function(XMLHttpRequest,textStatus, errorThrown){
              appcan.locStorage.remove("toUpgrade");
              console.log(XMLHttpRequest.status);//HTTP状态码;
              console.log(XMLHttpRequest.responseText);//服务器响应返回的文本文本信息
              console.log(textStatus);//返回状态;
              console.log(errorThrown);//服务器抛出的错误信息
              appcan.window.openToast("无法连接到服务器，请稍后再试...",2000,5,0);
            }
          })
        }
         function pullToRefresh_loadMore(){
                appcan.window.setBounce({
                    bounceType: "0", //弹动的类型,如果为多个请用数组,0：向下拖动，1:向上拖动;
                    startPullCall: function(type) { //开始滑动时触发回调
                    },
                    downEndCall: function(type){ //上拉超过边界或者下拉执行回调
                    },
                    upEndCall: function(type){ //上拉或者下拉,超出边界之后,恢复最初状态执行
                        setTimeout(function(){
                            appcan.window.resetBounceView(type);
                            var setBounce=appcan.locStorage.getVal("setBounce");
                            if(setBounce !== "true"){
                                if(!type){
                                        userList();
                                        appcan.locStorage.setVal("setBounce","true");
                                }
                            }else{
                                 //在没有请求数据成功的情况下 页面下拉或者上拉无效。。。
                                return false;
                            }
                        },1000);
                    },
                    color: '#f0f0f0', // 如果超出了边界显示的背景颜色
                    imgSettings: {
                        // 如果超出了边界,并且想要设置 显示的内容包括图片文字则设置该参数
                        'imagePath': 'res://shuaxin.png',
                        'textColor': '#88c933',
                        'pullToReloadText': '拖动刷新...',
                        'releaseToReloadText': '释放刷新...',
                        "loadingText": '加载中,请稍等...'
                    }
                });      
        } 
    </script>
</html>
